/*
 * Copyright (C) 2019 MediaTek Inc.
 * Copyright (C) 2021 XiaoMi, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See http://www.gnu.org/licenses/gpl-2.0.html for more details.
 */

/dts-v1/;
/plugin/;
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/pinctrl/mt6768-pinfunc.h>

&reserved_memory {
	reserve-memory-scp_share {
		compatible = "mediatek,reserve-memory-scp_share";
		no-map;
		size = <0 0x00d00000>;
		alignment = <0 0x1000000>;
		alloc-ranges = <0 0x40000000 0 0x50000000>;
	};
};

/* chosen */
&chosen {

	atag,videolfb-fb_base_l = <0x7e605000>;
	atag,videolfb-fb_base_h = <0x0>;
	atag,videolfb-islcmfound = <1>;
	atag,videolfb-islcm_inited = <0>;
	atag,videolfb-fps= <6000>;
	atag,videolfb-vramSize= <0x017e8000>;
	atag,videolfb-lcmname=
		"hx83112b_fhdp_dsi_cmd_auo_rt5081_drv";
};

&odm {
	led0:led@0 {
		compatible = "mediatek,red";
		led_mode = <0>;
		data = <1>;
		pwm_config = <0 0 0 0 0>;
	};
	led1:led@1 {
		compatible = "mediatek,green";
		led_mode = <0>;
		data = <1>;
		pwm_config = <0 0 0 0 0>;
	};
	led2:led@2 {
		compatible = "mediatek,blue";
		led_mode = <0>;
		data = <1>;
		pwm_config = <0 0 0 0 0>;
	};
	led3:led@3 {
		compatible = "mediatek,jogball-backlight";
		led_mode = <0>;
		data = <1>;
		pwm_config = <0 0 0 0 0>;
	};
	led4:led@4 {
		compatible = "mediatek,keyboard-backlight";
		led_mode = <0>;
		data = <1>;
		pwm_config = <0 0 0 0 0>;
	};
	led5:led@5 {
		compatible = "mediatek,button-backlight";
		led_mode = <0>;
		data = <1>;
		pwm_config = <0 0 0 0 0>;
	};
	led6:led@6 {
		compatible = "mediatek,lcd-backlight";
		led_mode = <4>;
		data = <1>;
		pwm_config = <0 3 0 0 0>;
	};
	vibrator0:vibrator@0 {
		compatible = "mediatek,vibrator";
		vib_timer = <25>;
		vib_limit = <9>;
		vib_vol= <11>;
	};
};

&board_id {
	io-channels = <&auxadc 3>;
	io-channel-names = "board_id-channel";
	hw_id-gpios = <&pio 158 0>;
	board_id2-gpios = <&pio 5 0>;
	board_id3-gpios = <&pio 6 0>;
	status = "okay";
};



/* flashlight start */
&flashlights_led191 {
	pinctrl-names = "default", "hw_ch0_high",
		"hw_ch0_low", "hw_ch1_high",
		"hw_ch1_low";
	pinctrl-0 = <&flashlight_pins_default>;
	pinctrl-1 = <&flashlight_pins_en_output1>;
	pinctrl-2 = <&flashlight_pins_en_output0>;
	pinctrl-3 = <&flashlight_pins_sel_output1>;
	pinctrl-4 = <&flashlight_pins_sel_output0>;
	status = "okay";
};
&pio {
	flashlight_pins_default: flashlightdefault {
	};
	flashlight_pins_en_output1: flashlightenoutput1 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO152__FUNC_GPIO152>;
			slew-rate = <1>;
			output-high;
		};
	};
	flashlight_pins_en_output0: flashlightenoutput0 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO152__FUNC_GPIO152>;
			slew-rate = <1>;
			output-low;
		};
	};
	flashlight_pins_sel_output1: flashlightseloutput1 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO153__FUNC_GPIO153>;
			slew-rate = <1>;
			output-high;
		};
	};
	flashlight_pins_sel_output0: flashlightseloutput0 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO153__FUNC_GPIO153>;
			slew-rate = <1>;
			output-low;
		};
	};
};
/* flashlight end*/
/* TOUCH start */
&touch {
	tpd-resolution = <1080 2160>;
	use-tpd-button = <0>;
	tpd-key-num = <3>;
	tpd-key-local= <139 172 158 0>;
	tpd-key-dim-local = <90 883 100 40 230
				883 100 40 370 883 100 40 0 0 0 0>;
	tpd-max-touch-num = <10>;
	tpd-filter-enable = <0>;
	tpd-filter-pixel-density = <168>;
	tpd-filter-custom-prameters = <0 0 0 0 0 0 0 0 0 0 0 0>;
	tpd-filter-custom-speed = <0 0 0>;
	pinctrl-names = "default", "state_eint_as_int",
		"state_eint_output0", "state_eint_output1",
		"state_rst_output0", "state_rst_output1";
	pinctrl-0 = <&ctp_pins_default>;
	pinctrl-1 = <&ctp_pins_eint_as_int>;
	pinctrl-2 = <&ctp_pins_eint_output0>;
	pinctrl-3 = <&ctp_pins_eint_output1>;
	pinctrl-4 = <&ctp_pins_rst_output0>;
	pinctrl-5 = <&ctp_pins_rst_output1>;
	status = "okay";
};
&pio {
	ctp_pins_default: eint0default {
	};
	ctp_ts_pins_default: eint1default {
	};
	ctp_pins_eint_as_int: eint@0 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO1__FUNC_GPIO1>;
			slew-rate = <0>;
			bias-disable;
		};
	};
	ctp_pins_eint_output0: eintoutput0 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO1__FUNC_GPIO1>;
			slew-rate = <1>;
			output-low;
		};
	};
	ctp_pins_eint_output1: eintoutput1 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO1__FUNC_GPIO1>;
			slew-rate = <1>;
			output-high;
	};
	};
	ctp_pins_rst_output0: rstoutput0 {
		pins_cmd_dat {
				pinmux = <PINMUX_GPIO92__FUNC_GPIO92>;
				slew-rate = <1>;
				output-low;
			};
	};
	ctp_pins_rst_output1: rstoutput1 {
		pins_cmd_dat {
				pinmux = <PINMUX_GPIO92__FUNC_GPIO92>;
				slew-rate = <1>;
				output-high;
		};
	};

};
/* TOUCH end */

/* add goodix fingerprint start*/


&spi2 {
	status = "ok";
	#address-cells = <1>;
	#size-cells = <0>;
	fpc_tee@0 {
		compatible = "goodix,goodix-fp";
		reg = <0>;
		fpc,enable-wakeup;
		spi-max-frequency = <10000000>;
		netlink-event = <30>;
		status = "okay";
	};
};

&goodix_fp {
	fpc,gpio_irq = <&pio 8 0>;
	pinctrl-names = "default", "reset_high", "reset_low", "spi_cs_low", "spi_cs_high";
	pinctrl-0 = <&fingerprint_default>;
	pinctrl-1 = <&fingerprint_reset_high>;
	pinctrl-2 = <&fingerprint_reset_low>;
	pinctrl-3 = <&fingerprint_spi_cs_low>;
	pinctrl-4 = <&fingerprint_spi_cs_high>;
	status = "okay";
};

&pio {
	fingerprint_default: state_default {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO8__FUNC_MD_INT0>;
			slew-rate = <0>;
			bias-disable;
		};
	};
	fingerprint_reset_high: state_reset_high {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO31__FUNC_GPIO31>;
			slew-rate = <1>;
			output-high;
		};
	};
	fingerprint_reset_low: state_reset_low {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO31__FUNC_GPIO31>;
			slew-rate = <1>;
			output-low;
		};
	};

	fingerprint_spi_cs_low: state_spi_cs_low {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO25__FUNC_SPI2_CSB>;
			slew-rate = <1>;
			output-low;
		};
	};
	fingerprint_spi_cs_high: state_spi_cs_high {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO25__FUNC_SPI2_CSB>;
			slew-rate = <1>;
			output-high;
		};
	};

	ctp_ts_int_active: int_active {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO1__FUNC_GPIO1>;
			slew-rate = <0>;
			bias-pull-up = <11>;
		};
	};
	ctp_ts_reset_active: reset_active {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO23__FUNC_GPIO23>;
			slew-rate = <1>;
			output-high;
		};
	};
	ctp_ts_int_suspend: int_suspend {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO1__FUNC_GPIO1>;
			slew-rate = <1>;
			output-low;
		};
	};
	ctp_ts_reset_suspend: reset_suspend {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO23__FUNC_GPIO23>;
			slew-rate = <1>;
			output-low;
		};
	};
};
/* add goodix fingerprint end*/

/* AWINIC AW87519 Smart PA */
&i2c7 {
	aw87519@58 {
			compatible = "awinic,aw87519_pa";
			reg = <0x58>;
			reset-gpio = <&pio 22 0>;
			status = "okay";
	};
};
/* AWINIC AW87519 Smart PA End */

&i2c7 {
	fusb303@21 {
		status = "ok";
		compatible = "on,fusb303";
		reg = <0x21>;
		interrupt-parent = <&pio>;
		interrupts = <41 0x2>;
		fusb303,int-gpio = <&pio 41 0>;
		fusb303,init-mode = <20>;			/* trysnk, DRP */
		fusb303,host-current = <2>;			/* 180uA host current */
		fusb303,drp-toggle-time =  <1>;			/* 70ms */
		fusb303,drp-duty-time = <0>;			/* 60 duty time */
		fusb303,autosink-threshold = <1>;		/* 3P1V */
		fusb303,cc-debounce-time = <3>;			/* 150ms */
	};
};


&i2c7 {
	smb1351-charger@55 {
		compatible = "qcom,smb1351_charger";
		reg = <0x55>;
		interrupt-parent = <&pio>;
		interrupts = <20 IRQ_TYPE_EDGE_FALLING 20 0>;
		qcom,recharge-disabled;
		qcom,bc12_supported;
		/* qcom,smb1351_susp = <&pio 21 0x0>; */
		/* mi,connect_therm = <&pio 127 0x0>; */

		charger_name = "primary_chg";
		/*charger_name = "secondary_chg";*/
		ichg = <1800000>; /* uA */
		mivr = <4500000>; /* uV */
		cv = <4396000>; /* uV */
		ieoc = <200000>; /* uA */
		safety_timer = <12>; /* hour */
		en_st; /* safety timer */
		/* en_te; */
		en_wdt;
	};

};
&lk_charger  {
	/* charging current */
	ac_charger_current = <1000000>;
	non_std_ac_charger_current = <1000000>;

	/* battery temperature protection */
	temp_t4_threshold = <55>;
	temp_t3_threshold = <45>;
	temp_t1_threshold = <0>;
};

&charger {
	algorithm_name = "SwitchCharging";

	set_cap_delay = <10>;
	enable_sw_jeita;
	battery_cv = <4460000>;
	usb_charger_current_suspend = <0>;
	usb_charger_current_unconfigured = <70000>;
	usb_charger_current_configured = <500000>;
	usb_charger_current = <500000>;
	ac_charger_current = <2050000>;
	ac_charger_input_current = <2050000>;
	non_std_ac_charger_current = <1000000>;
	charging_host_charger_current = <1500000>;
	apple_1_0a_charger_current = <650000>;
	apple_2_1a_charger_current = <800000>;
	ta_ac_charger_current = <2050000>;
	hvdcp_charger_current = <3000000>;

	pd_vbus_upper_bound = <9000000>;


	/* sw jeita */
	jeita_temp_above_t4_cv = <4100000>;
	jeita_temp_t3_to_t4_cv = <4100000>;
	jeita_temp_t2_to_t3_cv = <4460000>;
	jeita_temp_t1_to_t2_cv = <4460000>;
	jeita_temp_t0_to_t1_cv = <4460000>;
	jeita_temp_below_t0_cv = <4460000>;


	jeita_temp_t3_to_t4_cc = <2400000>;
	jeita_temp_t2_to_t3_cc = <3000000>;
	jeita_temp_t1_to_t2_cc = <2400000>;
	jeita_temp_t0_to_t1_cc = <1000000>;

	temp_t4_thres = <55>;
	temp_t4_thres_minus_x_degree = <53>;
	temp_t3_thres = <45>;
	temp_t3_thres_minus_x_degree = <43>;
	temp_t2_thres = <15>;
	temp_t2_thres_plus_x_degree = <13>;
	temp_t1_thres = <5>;
	temp_t1_thres_plus_x_degree = <4>;
	temp_t0_thres = <0>;
	temp_t0_thres_plus_x_degree = <0>;
	temp_neg_10_thres = <0>;

	/* battery temperature protection */
	enable_min_charge_temp;
	min_charge_temp = <0>;
	min_charge_temp_plus_x_degree = <2>;
	max_charge_temp = <55>;
	max_charge_temp_minus_x_degree = <53>;

	qcom,thermal-mitigation-dcp
		= <1800000 1800000 1800000 1800000 1800000 1800000 1800000
		1800000 1800000 1800000 1800000 1800000 1600000 1400000
		1200000 1000000>;
	qcom,thermal-mitigation-qc3
		= <2700000 2570000 2400000 2270000 2120000 1965000 1820000
		1650000 1500000 1375000 1225000 1100000 975000 825000
		675000 475000>;
	qcom,thermal-mitigation-qc2
		= <1625000 1625000 1625000 1625000 1625000 1525000 1425000
		1325000 1225000 1125000 1025500 925000 825000 725000
		625000 525000>;
	qcom,thermal-mitigation-pd-base
		= <3000000 2800000 2600000 2400000 2200000 2000000 1800000
		1600000 1600000 1400000 1200000 1100000 1000000 900000
		752500 525000>;
};




&i2c2 {
	clock-frequency = <400000>;

	mtk-usb@60 {
		compatible = "mediatek,mtk-usb";
		reg = <0x60>;
		status = "okay";
	};
};

&i2c0 {
	lm3697@36 {
		compatible = "ti,lm3697";
		reg = <0x36>;

		status = "okay";
		enable-gpios = <&pio 160 0>;

		backlight {
			compatible = "ti,lm3697-backlight";

			lcd {
				led-sources = <0 1 2>;
				ramp-up-msec = <200>;
				ramp-down-msec = <200>;
				pwm-period = <0>;
				default-brightness-level = <255>;
			};
		};
		fault-monitor {
			compatible = "ti,lm3697-fault-monitor";
		};
	};

	ktd@37 {
	compatible = "ktd,ktd3137";
	reg = <0x37>;
	status = "okay";
	/*ktd,pwm-mode; */
	ktd,using-lsb = <1>;
	ktd,pwm-frequency = <100>;
	ktd,bl-fscal-led = <0x98>;/*default 20.2mA*/
	ktd,turn-on-ramp = <0>;
	ktd,turn-off-ramp = <0>;
	ktd,pwm-trans-dim = <0>;
	ktd,i2c-trans-dim = <0>;
	ktd,bl-channel = <2>;
	ktd,ovp-level = <32>;/*default 32v*/
	ktd,switching-frequency = <1000>; /*default 1000kHz*/
	ktd,inductor-current = <2600>; //default 2600mA
	ktd,linear_ramp = <1>; /*default is exponential*/
	ktd,linear_backlight = <1>; /*default is exponential*/
    };

	lcd_bias@3e {
		compatible = "mediatek,lcd_bias";
		reg = <0x3e>;
		status = "okay";
	};
};

/* accdet start */
&accdet {
	/* accdet micbias voltage: 0x07,2.7v;0x05,2.5v;0x02,1.9v */
	accdet-mic-vol = <6>;
	headset-mode-setting = <0x500 0x500 1 0x1f0 0x800 0x800 0x20 0x44>;
	accdet-plugout-debounce = <1>;
	/*1:ACC mode, 2:low cost without in bias, 6:low cost with in bias*/
	accdet-mic-mode = <1>;
	/* eint_level_trigger: 8,LEVEL_LOW(DEF) ;4,LV_HIGH;others,LV_LOW */
	headset-eint-level-pol = <8>;
	/*0--MD_MAX--UP_MAX--DW_MAX*/
	headset-three-key-threshold = <0 80 220 400>;
	headset-three-key-threshold-CDD = <0 121 192 600>;
	/*0--MD_MAX--VOICE_MAX--UP_MAX--DW_MAX*/
	headset-four-key-threshold = <0 58 121 192 400>;
	status = "okay";
};
/* accdet end */

&mt6370_pmu {
	mt6370,intr_gpio_num = <20>; /* direct defined GPIO num */
	mt6370,intr_gpio = <&pio 20 0x0>;
};
&mt6370_typec {
	mt6370pd,intr_gpio_num = <41>; /* direct defined GPIO num */
	mt6370pd,intr_gpio = <&pio 41 0x0>;
	mt6370pd,usb_switch_gpio_num = <91>; /* direct defined GPIO num */
	mt6370pd,usb_switch_gpio = <&pio 91 0x0>;
};

/* CONSYS GPIO standardization */
&pio {
	consys_pins_default: consys_default {
	};
	gpslna_pins_init: gpslna@0 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO94__FUNC_GPIO94>;
			slew-rate = <0>;
			bias-disable;
			output-low;
		};
	};
	gpslna_pins_oh: gpslna@1 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO94__FUNC_GPIO94>;
			slew-rate = <1>;
			output-high;
		};
	};
	gpslna_pins_ol: gpslna@2 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO94__FUNC_GPIO94>;
			slew-rate = <1>;
			output-low;
		};
	};
};
&consys {
	pinctrl-names = "default", "gps_lna_state_init",
		"gps_lna_state_oh", "gps_lna_state_ol";
	pinctrl-0 = <&consys_pins_default>;
	pinctrl-1 = <&gpslna_pins_init>;
	pinctrl-2 = <&gpslna_pins_oh>;
	pinctrl-3 = <&gpslna_pins_ol>;
	status = "okay";
};
/* CONSYS end */

/* IRTX GPIO Start */
&irtx_pwm {
	pinctrl-names = "irtx_gpio_led_default", "irtx_gpio_led_set";
	pinctrl-0 = <&irtx_gpio_led_default>;
	pinctrl-1 = <&irtx_gpio_led_set>;
	status = "okay";
};
&pio {
	/* IRTX GPIO Settings -Start */
	/* default: GPIO0, output, high */
	irtx_gpio_led_default:irtx_gpio_led_def@gpio12 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO12__FUNC_GPIO12>;
			slew-rate = <1>;
			bias-disable;
			output-low;
			input-schmitt-enable = <0>;
		};
	};

	irtx_gpio_led_set:irtx_gpio_led_set@gpio12 {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO12__FUNC_PWM0>;
			slew-rate = <1>;
			output-high;
		};
	};
}; /* IRTX GPIO Settings -End */

/* DISPSYS GPIO standardization */
&pio {
	mtkfb_pins_lcm_rst_out1_gpio: lcm_rst_out1_gpio {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO45__FUNC_GPIO45>;
			slew-rate = <1>;
			output-high;
		};
	};

	mtkfb_pins_lcm_rst_out0_gpio: lcm_rst_out0_gpio {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO45__FUNC_GPIO45>;
			slew-rate = <1>;
			output-low;
		};
	};

	mtkfb_pins_lcm_dsi_te: lcm_dsi_te {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO44__FUNC_DSI_TE>;
		};
	};
};

&mtkfb {
	pinctrl-names =
		"lcm_rst_out1_gpio", "lcm_rst_out0_gpio",
		"mode_te_te";
	pinctrl-0 = <&mtkfb_pins_lcm_rst_out1_gpio>;
	pinctrl-1 = <&mtkfb_pins_lcm_rst_out0_gpio>;
	pinctrl-2 = <&mtkfb_pins_lcm_dsi_te>;
	status = "okay";
};
/* DISPSYS GPIO standardization end*/

#include <lancelot/cust.dtsi>
#include "mediatek/cust_mt6768_lancelot_camera.dtsi"
/*End of this file, DO NOT ADD ANYTHING HERE*/
